/*
 * \brief  Platform environment of Genode process
 * \author Norman Feske
 * \author Christian Helmuth
 * \date   2006-07-28
 *
 * This file is a generic variant of the platform environment, which is
 * suitable for platforms such as L4ka::Pistachio and L4/Fiasco. On other
 * platforms, it may be replaced by a platform-specific version residing
 * in the corresponding 'base-<platform>' repository.
 */

/*
 * Copyright (C) 2006-2009 Norman Feske
 * Genode Labs, Feske & Helmuth Systementwicklung GbR
 *
 * This file is part of the Genode OS framework, which is distributed
 * under the terms of the GNU General Public License version 2.
 */

#ifndef _INCLUDE__BASE__PLATFORM_ENV_H_
#define _INCLUDE__BASE__PLATFORM_ENV_H_

#include <base/env.h>

#include <base/heap.h>
#include <parent/client.h>
#include <ram_session/client.h>
#include <rm_session/client.h>
#include <cpu_session/client.h>
#include <pd_session/client.h>


namespace Genode {

	class Platform_env : public Env
	{
		private:

			Parent_client          _parent_client;
			Parent                *_parent;
			Ram_session_capability _ram_session_cap;
			Ram_session_client     _ram_session_client;
			Cpu_session_client     _cpu_session_client;
			Rm_session_client      _rm_session_client;
			Pd_session_client      _pd_session_client;
			Heap                   _heap;

		public:

			/**
			 * Standard constructor
			 */
			Platform_env()
			:
				_parent_client(Genode::parent_cap()), _parent(&_parent_client),
				_ram_session_cap(parent()->session("Env::ram_session", "")),
				_ram_session_client(_ram_session_cap),
				_cpu_session_client(Cpu_session_capability(parent()->session("Env::cpu_session", ""))),
				_rm_session_client(Rm_session_capability(parent()->session("Env::rm_session", ""))),
				_pd_session_client(Pd_session_capability(parent()->session("Env::pd_session", ""))),
				_heap(ram_session(), rm_session())
			{ }


			/**
			 * Constructor defining parent
			 */
			explicit Platform_env(Parent *p)
			:
				_parent_client(Parent_capability()), _parent(p),
				_ram_session_cap(Ram_session_capability(parent()->session("Env::ram_session", ""))),
				_ram_session_client(_ram_session_cap),
				_cpu_session_client(Cpu_session_capability(parent()->session("Env::cpu_session", ""))),
				_rm_session_client(Rm_session_capability(parent()->session("Env::rm_session", ""))),
				_pd_session_client(Pd_session_capability(parent()->session("Env::pd_session", ""))),
				_heap(ram_session(), rm_session())
			{ }


			/*******************
			 ** Env interface **
			 *******************/

			Parent                 *parent()          { return  _parent; }
			Ram_session            *ram_session()     { return &_ram_session_client; }
			Ram_session_capability  ram_session_cap() { return  _ram_session_cap; }
			Cpu_session            *cpu_session()     { return &_cpu_session_client; }
			Rm_session             *rm_session()      { return &_rm_session_client; }
			Pd_session             *pd_session()      { return &_pd_session_client; }
			Allocator              *heap()            { return &_heap; }
	};
}

#endif /* _INCLUDE__BASE__PLATFORM_ENV_H_ */
